package com.fast.manager.base.web.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.fast.commons.web.BaseController;
import com.fast.commons.web.model.AjaxResponse;
import com.fast.manager.base.domain.Dept;
import com.fast.manager.base.service.DeptService;

@Controller
@RequestMapping("/manager/base/dept")
public class DeptController extends BaseController {
	
	@Autowired
	private DeptService service ;

	/**
	 * 主页
	 * @return
	 */
	@RequestMapping(value="/main", method=RequestMethod.GET)
	public String main(Model model) {
		return viewName("main") ;
	}
	
	/**
	 * 表单页面
	 * @param id
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/form", method=RequestMethod.GET)
	public String form(Long id, Model model) {
		if(null != id) {
			model.addAttribute("id", id) ;
		}
		return viewName("form") ;
	}
	
	/**
	 * 添加
	 * @param dto
	 * @return
	 */
	@RequestMapping(value="/add", method=RequestMethod.POST)
	public @ResponseBody AjaxResponse add(Dept dto) {
		return this.service.add(dto);
	}
	
	/**
	 * 删除
	 * @param ids 数组
	 * @return
	 */
	@RequestMapping(value="/delete/{id}", method=RequestMethod.DELETE)
	public @ResponseBody AjaxResponse delete(@PathVariable Integer id) {
		return this.service.delete(id) ;
	}
	
	/**
	 * 修改
	 * @param dto
	 * @return
	 */
	@RequestMapping(value="/update", method=RequestMethod.POST)
	public @ResponseBody AjaxResponse update(Dept dto) {
		return this.service.update(dto);
	}
	
	/**
	 * 根据ID获取数据
	 * @param id
	 * @return
	 */
	@RequestMapping(value="/get/{id}", method=RequestMethod.GET)
	public @ResponseBody Dept get(@PathVariable Long id) {
		return this.service.get(id) ;
	}
	
	/**
	 * 部门管理
	 * @param dto
	 * @return
	 */
	@RequestMapping(value="/treegrid/{companyId}", method=RequestMethod.GET)
	public @ResponseBody List<Dept> treegrid(@PathVariable Integer companyId) {
		return this.service.treegrid(companyId) ;
	}
	
}
